---
description: "Swift documentation for 'withUnsafeMutablePointer'"
keywords: ""
layout: "default"
root: "/v5.1"
title: "withUnsafeMutablePointer"
---

<div class="intro-declaration"><code class="language-swift">func withUnsafeMutablePointer(to:_:)(to value: inout T, _ body: (UnsafeMutablePointer&lt;T>) throws -> Result) rethrows -> Result</code></div><div class="discussion comment"><p>Calls the given closure with a mutable pointer to the given argument.
</p>
<p>The <code>withUnsafeMutablePointer(to:_:)</code> function is useful for calling
Objective-C APIs that take in/out parameters (and default-constructible
out parameters) by pointer.</p>
<p>The pointer argument to <code>body</code> is valid only during the execution of
<code>withUnsafeMutablePointer(to:_:)</code>. Do not store or return the pointer for
later use.</p>
</div>